package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 使用预编译可以有效解决
 */
public class JdbcDemo7 {
    public static void main(String[] args) {
        UserInfo userInfo=InputUtil.getInputObject(new UserInfo(),"欢迎登录","登录");
        System.out.println(userInfo);
        try( Connection con=DBUtil.getConnection()) {
           String sql="SELECT username,password,nickname,age "+"FROM userinfo "+"WHERE username=? AND password=?";
            PreparedStatement pr=con.prepareStatement(sql);
            pr.setString(1,userInfo.getUsername());
            pr.setString(2,userInfo.getPassword());
            ResultSet rs=pr.executeQuery();
            if (rs.next()){
                System.out.println("成功");
            }else{
                System.out.println("失败");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
